﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;

namespace BarcodeHandlerForms
{
    public partial class PasswordForm : Form
    {

        public bool isValidate = false;
        public PasswordForm()
        {
            InitializeComponent();
        }

        private void btnVlidate_Click(object sender, EventArgs e)
        {
            string password = Utils.GetConfiguration().AppSettings.Settings["Password"].Value;
            string validatePassword = this.txtPassword.Text;

            SHA1 sha1 = SHA1.Create();
            byte[] originalPwd = Encoding.UTF8.GetBytes(validatePassword);
            byte[] encryPwd = sha1.ComputeHash(originalPwd);
            validatePassword = string.Join("", encryPwd.Select(b => string.Format("{0:x2}",b)).ToArray()).ToUpper();

            if (string.IsNullOrWhiteSpace(validatePassword))
            {
                MessageBox.Show("请输入验证密码！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (password != validatePassword) 
            {
                MessageBox.Show("密码不正确", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            isValidate = true;
            this.Hide();
        }
    }
}
